using System;
using System.Data;
using System.Xml;
using System.Text;
using System.Collections.Generic;

namespace AliCMS
{
    public interface IManager
    {
        string MapPath(string path);
        string GetWebPath();
        string GetCachePath();
        string GetCommonPath();
        string GetCssPath(string skinPath);
        string GetImagePath(string skinPath);
        string GetJsPath(string templatePath);
        string GetDataPath(object instanceID, string lang);
        string GetTemplatePath(string templatePath);
        string GetCachedTemplatePath(string templatePath, string langAb, bool isDebug);
        string GetSkinPath(DataRow channel);
        string GetSkinPath(string skinPath);
        string GetModulePath(string ns);

        DataRow GetChannel(string path);

        string GetPathInChannel(DataRow channel, string pathInTemplate);
        string GetPathInChannel(DataRow channel, string pathInTemplate, string templatePath);

        IObject CreateObject(string objectName, int instanceID, string lang);
        IObject CreateObject(string objectName, int instanceID, string lang, bool checkRight);
        IObject CreateObject(string objectName, int instanceID, string lang, bool checkRight, string database);

        DataTable Instances { get; }
        DataTable Channels { get; }
        DataTable Languages { get;}
        DataTable Pages { get;}

        StringBuilder Build(XmlNode template, DataTable data, Dictionary<string, object> replacementPair);
        StringBuilder Build(XmlNode template, DataTable data, Dictionary<string, object> replacementPair, ref object current, ref int index);
        StringBuilder Build(XmlNode template, DataRow[] data, Dictionary<string, object> replacementPair);
        StringBuilder BuildTree(XmlNode template, DataTable data, Dictionary<string, object> replacementPair, string rootID, string parentIDField, string idField, ref object current, ref int index);

        DataTable SplitToTable(params object[] list);
        Dictionary<string, object> ParseContent(object allContent, Page page);

        DataTable GetPath(DataRow channel);
        DataTable GetPath(string url, string lang);
        
        void InitSystem();

        string GenerateRandomPassword(int bitCount);
        DataRow GetExtraInstance(DataRow channel, string mark);

        bool HasRight(string userID, int instanceInnerID, string lang, object objectIDOrName, object operationIDOrName, Guid recordID);
        bool HasRight(string userID, int instanceInnerID, Guid? subInstanceID, string lang, object objectIDOrName, object operationIDOrName, Guid recordID);
        
        void UpdateSite(string type, string lang);
        void UpdateExtraInstances();
        void UpdateRoles();
        void UpdatePrivileges();
        void UpdatePermissions();
        void UpdateInstances();
        void UpdateChannels();
        void UpdateLanguages();
        void UpdatePages();
        void UpdateRewrite();
        void UpdateTask();
		void UpdateClients();
		void UpdateBlackList();
		void UpdateWhiteList();
		void UpdateKeywordFilter();

        void MakeSureFolderExist(string path);
        string MakeClassName(string pathInTemplate);
        string AccessEscapeWildcard(string source);
		void SmartUpdate(Dictionary<string, object> update);
        void ClearAllCache();
        string Escape(object text);
        bool HasUyghurText(object text);
        string Translate(string text, string from, string to);
        void DeleteFolder(string path, bool recursive);
        string HtmlToText(object html);
        string MakeValidateKey();
        string GetConnectionString(int instanceID, string db);

        Dictionary<string, string> User { get; }
        void AddToUser(string key, string value);
        void AddToUser(Dictionary<string, string> kvs);

        DataTable Objects { get; }
        DataTable Properties { get; }
        DataTable Roles { get; }
        bool IsClient { get; }
        Dictionary<string, string> Site { get; }

        void EncodeGZipToFile(string text, string path);
        string DecodeGZipToText(string path);

        void AddWaterMark(string path, string lang);
        void AddWaterMark(string path, string lang, Dictionary<string, string> config);

        void Login(Dictionary<string, string> profile, int minutes);
        void Login(Dictionary<string, string> profile, int minutes, bool isRootDomain);
        void Logout();

		string BuildJson(object result);

		void Log(String title, String message, String lang);
	}
}
